import { Injectable, Logger } from '@nestjs/common';
import { LogService } from '../log/log.service';
import { DashboardMetric } from './data.type';
import { MissionLogService } from '../mission/mission-log/mission-log.service';
import { create, round } from 'lodash';
import { UserService } from '../user/user.service';
import { StandardPagination } from '~/helper/paginate';
import { ArticleContentCollectService } from '../article/article-content/article-content-collect/article-content-collect.service';
import { ArticleContentLikeService } from '../article/article-content/article-content-like/article-content-like.service';
import { PointsService } from '../points/points.service';
import { ArticleContentService } from '../article/article-content/article-content.service';
import {
  ArticleContentEntity,
  ArticleContentType,
} from '../article/article-content/article-content.entity';
import { FeedbackService } from '../feedback/feedback.service';
import dayjs from 'dayjs';
import { PointsLogService } from '../points/points-log/points-log.service';
import { ArticleContentUserReviewService } from '../article/article-content/article-content-user-review/article-content-user-review.service';
import { ArticleContentShareService } from '../article/article-content/article-content-share/article-content-share.service';
import { MissionType } from '../mission/mission.model';

@Injectable()
export class DataService {
	private readonly logger = new Logger(DataService.name);

  constructor(
    private readonly logService: LogService,
    private readonly missionLogService: MissionLogService,
    private readonly userService: UserService,
    private readonly articleContentLikeService: ArticleContentLikeService,
    private readonly articleContentCollectService: ArticleContentCollectService,
    private readonly pointsService: PointsService, // 假设你有一个 PointsService 用于处理积分相关逻辑
    private readonly articleContentService: ArticleContentService,
    private readonly feedbackService: FeedbackService, // 假设你有一个 FeedbackService 用于处理反馈相关逻辑
    private readonly pointsLogService: PointsLogService, // 假设你有一个 PointsLogService 用于处理积分日志相关逻辑
    private readonly articleContentUserReviewService: ArticleContentUserReviewService,
    private readonly articleContentShareService: ArticleContentShareService
  ) {}

  /**
   * 获取今日阅读量
   * @returns 今日阅读量
   */
  async getTodayReadingCount(): Promise<DashboardMetric> {
    const [today, lastday] = await this.logService.getTodayOrLastdayReadingCount();

    return {
      value: today,
      baseValue: lastday,
      trend: today > lastday ? 'UP' : today < lastday ? 'DOWN' : 'FLAT',
      changePercent: Math.abs(round(((today - lastday) / lastday) * 100, 2)),
      unit: '次',
    };
  }

  /**
   * 获取今日任务完成总数
   * @returns 今日任务完成总数
   */
  async getTodayTaskCount(): Promise<DashboardMetric> {
    const [today, lastday] = await this.missionLogService.getTodayOrLastdayTaskCount();

    return {
      value: today,
      baseValue: lastday,
      trend: today > lastday ? 'UP' : today < lastday ? 'DOWN' : 'FLAT',
      changePercent: Math.abs(round(((today - lastday) / lastday) * 100, 2)),
      unit: '次',
    };
  }

  /**
   * 获取今日答题次数
   * @returns 今日答题次数
   */
  async getTodayOrLastdayQuizCount(): Promise<DashboardMetric> {
    const [today, lastday] = await this.logService.getTodayOrLastdayQuizCount();

    return {
      value: today,
      baseValue: lastday,
      trend: today > lastday ? 'UP' : today < lastday ? 'DOWN' : 'FLAT',
      changePercent: Math.abs(round(((today - lastday) / lastday) * 100, 2)),
      unit: '次',
    };
  }

  /**
   * 获取今日答题正确率
   * @returns 今日答题正确率
   */
  async getTodayOrLastdayQuizRate(): Promise<DashboardMetric> {
    const [today, lastday] = await this.logService.getTodayOrLastdayQuizScore();

    return {
      value: Math.abs(round(today * 100, 2)),
      baseValue: Math.abs(round(lastday * 100, 2)),
      trend: today > lastday ? 'UP' : today < lastday ? 'DOWN' : 'FLAT',
      changePercent: Math.abs(round(((today - lastday) / lastday) * 100, 2)),
      unit: '%',
    };
  }

  /**
   * 获取面板数据 - 今日阅读量、今日任务完成总数、今日答题次数、答题正确率
   * @returns 面板数据数组
   */
  async getPanelData(): Promise<DashboardMetric[]> {
    const readingCount = await this.getTodayReadingCount();
    const taskCount = await this.getTodayTaskCount();
    const quizCount = await this.getTodayOrLastdayQuizCount();
    const quizRate = await this.getTodayOrLastdayQuizRate();
    return [readingCount, taskCount, quizCount, quizRate];
  }

  /**
   * 为用户添加统计信息的私有方法
   * @param user 用户对象
   * @returns 带统计信息的用户对象
   */
  private async addUserStats(user: any): Promise<any> {
    // 获取用户阅读量统计
    const [todayReading, totalReading] = await this.logService.getUserReadingCount(user.id);

    // 获取用户任务完成统计
    const [todayTasks, totalTasks] = await this.missionLogService.getUserTaskCount(user.id);

    // 获取用户答题统计
    const [todayQuizCount, totalQuizCount, todayQuizRate, totalQuizRate, topQuizRate] =
      await this.logService.getUserQuizStats(user.id);

    // 获取用户点赞量统计
    const userLikeCount = await this.articleContentLikeService.getUserLikeCount(user.id);

    // 获取用户收藏量统计
    const userCollectCount = await this.articleContentCollectService.getUserCollectCount(user.id);

    // 获取用户积分
    const userPoints = await this.pointsService.getPointsByUserId(user.id);

    // 获取用户平均阅读时长统计
    const [todayAverageReadingDuration, totalAverageReadingDuration] =
      await this.logService.getUserAverageReadingDuration(user.id);

    return {
      ...user,
      knowledgePoints: userPoints?.value ?? 0, // 假设 userPoints 有 value 属性表示积分
      stats: {
        reading: {
          today: todayReading,
          total: totalReading,
        },
        tasks: {
          today: todayTasks,
          total: totalTasks,
        },
        quiz: {
          todayCount: todayQuizCount,
          totalCount: totalQuizCount,
          todayCorrectRate: Math.abs(round(todayQuizRate * 100, 2)), // 转换为百分比
          totalCorrectRate: Math.abs(round(totalQuizRate * 100, 2)), // 转换为百分比
					topCorrectRate: Math.abs(round(topQuizRate * 100, 2)), // 转换为百分比
        },
        likes: {
          total: userLikeCount,
        },
        collects: {
          total: userCollectCount,
        },
        readingDuration: {
          todayAverage: todayAverageReadingDuration, // 今日平均阅读时长(秒)
          totalAverage: totalAverageReadingDuration, // 总体平均阅读时长(秒)
        },
      },
    };
  }

  /**
   * 获取面板数据 - 用户列表
   * @param page 页码
   * @param pageSize 每页大小
   * @param diseaseId 疾病ID
   * @param keyword 关键词
   * @returns 用户列表
   */
  async getPanelDataWithUser({
    page = 1,
    pageSize = 10,
    diseaseId,
    keyword,
  }: {
    page?: number;
    pageSize?: number;
    diseaseId?: number;
    keyword?: string;
  }): Promise<StandardPagination<any>> {
    const userList: StandardPagination<any> = await this.userService.getAppUserByPage({
      page,
      pageSize,
      diseaseId,
      keyword,
    });

    // 为每个用户添加统计信息
    if (userList.data && userList.data.length > 0) {
      const usersWithStats = await Promise.all(
        userList.data.map(async (user) => await this.addUserStats(user))
      );

      return {
        ...userList,
        data: usersWithStats,
      };
    }

    return userList;
  }

  /**
   * 导出用户列表数据
   * @param diseaseId 疾病ID
   * @param keyword 关键词
   * @returns 带统计信息的用户列表
   */
  async exportPanelUserList(
    diseaseId?: number,
    keyword?: string
  ): Promise<{ columns: Record<string, any>[]; data: Record<string, any>[] }> {
    const users = await this.userService.getAllAppUsers({
      diseaseId,
      keyword,
    });

    const columns = [
      { header: '用户ID', key: '用户ID', width: 20 },
      { header: '微信昵称', key: '微信昵称', width: 28 },
      { header: '手机号', key: '手机号', width: 23 },
      { header: '年龄', key: '年龄', width: 18 },
      { header: '健康积分', key: '健康积分', width: 22 },
      { header: '知识积分', key: '知识积分', width: 22 },
      { header: '疾病类型', key: '疾病类型', width: 26 },
      { header: '阅读量', key: '阅读量', width: 20 },
      { header: '平均阅读时长', key: '平均阅读时长', width: 26 },
      { header: '收藏量', key: '收藏量', width: 20 },
      { header: '点赞量', key: '点赞量', width: 20 },
      { header: '完成任务量', key: '完成任务量', width: 22 },
      { header: '平均答题正确率', key: '答题正确率', width: 22 },
			{ header: '最高答题正确率', key: 'topCorrectRate', width: 22 },
      { header: 'BMI', key: 'BMI', width: 18 },
      { header: '血压(mmHg)', key: '血压(mmHg)', width: 24 },
      { header: '空腹血糖(mmol/L)', key: '空腹血糖(mmol/L)', width: 28 },
      { header: '低密度脂蛋白(mmol/L)', key: '低密度脂蛋白(mmol/L)', width: 32 },
      { header: '血尿酸(μmol/L)', key: '血尿酸(μmol/L)', width: 26 },
      { header: '注册时间', key: 'createTime', width: 26 },
    ];

    // 格式化阅读时长的辅助函数
    const formatReadingTime = (time: number): string => {
      if (time < 60) {
        // 小于60秒，显示秒
        return `${Math.round(time)}秒`;
      } else if (time < 3600) {
        // 小于1小时，显示分钟和秒
        const minutes = Math.floor(time / 60);
        const seconds = Math.round(time % 60);
        if (seconds > 0) {
          return `${minutes}分${seconds}秒`;
        } else {
          return `${minutes}分钟`;
        }
      } else {
        // 大于等于1小时，显示小时和分钟
        const hours = Math.floor(time / 3600);
        const minutes = Math.round((time % 3600) / 60);
        if (minutes > 0) {
          return `${hours}小时${minutes}分钟`;
        } else {
          return `${hours}小时`;
        }
      }
    };

    // 为每个用户添加统计信息并格式化导出数据
    if (users && users.length > 0) {
      const usersWithStats = await Promise.all(
        users.map(async (user) => await this.addUserStats(user))
      );

      // 格式化数据以匹配前端展示逻辑
      const formattedData = usersWithStats.map((user) => ({
        用户ID: user?.id,
        微信昵称: user?.wechat?.nickname ?? '-',
        手机号: user?.wechat?.phone ?? '-',
        年龄: user?.wechat?.age || '-',
        健康积分: user?.wechat?.healthPoints || 0,
        知识积分: user?.knowledgePoints || 0,
        疾病类型: user?.disease?.name || '无',
        阅读量: `${user?.stats?.reading?.total || 0}篇`,
        平均阅读时长: formatReadingTime(user?.stats?.readingDuration?.totalAverage || 0),
        收藏量: `${user?.stats?.collects?.total || 0}个`,
        点赞量: `${user?.stats?.likes?.total || 0}个`,
        完成任务量: `${user?.stats?.tasks?.total || 0}个`,
        答题正确率: `${user?.stats?.quiz?.totalCorrectRate || 0}%`,
        BMI: (parseFloat(user?.wechat?.bmi) || 0).toFixed(1),
        '血压(mmHg)': `${user?.wechat?.bloodPressureSbp || 0}/${
          user?.wechat?.bloodPressureDbp || 0
        }`,
        '空腹血糖(mmol/L)': (parseFloat(user?.wechat?.fastingBloodGlucose) || 0).toFixed(1),
        '低密度脂蛋白(mmol/L)': (parseFloat(user?.wechat?.ldlCholesterol) || 0).toFixed(1),
        '血尿酸(μmol/L)': (parseFloat(user?.wechat?.uricAcid) || 0).toFixed(0),
				createTime: dayjs(user?.createdAt).format('YYYY-MM-DD HH:mm:ss'),
				topCorrectRate: `${user?.stats?.quiz?.topCorrectRate || 0}%`,
      }));

      return { columns, data: formattedData };
    }

    return { columns, data: [] };
  }

  async addArticleStats(
    article: ArticleContentEntity
  ): Promise<{ readTime: number; averageReadTime: number }> {
    const [totalDuration, averageDuration, readCount] =
      await this.logService.getArticleReadingStats(article.id);

    return {
      readTime: totalDuration,
      averageReadTime: averageDuration,
    };
  }

  async exportPanelArticleList(): Promise<{
    columns: Record<string, any>[];
    data: Record<string, any>[];
  }> {
    // 格式化阅读时长的辅助函数
    const formatReadingTime = (time: number): string => {
      if (time < 60) {
        // 小于60秒，显示秒
        return `${Math.round(time)}秒`;
      } else if (time < 3600) {
        // 小于1小时，显示分钟和秒
        const minutes = Math.floor(time / 60);
        const seconds = Math.round(time % 60);
        if (seconds > 0) {
          return `${minutes}分${seconds}秒`;
        } else {
          return `${minutes}分钟`;
        }
      } else {
        // 大于等于1小时，显示小时和分钟
        const hours = Math.floor(time / 3600);
        const minutes = Math.round((time % 3600) / 60);
        if (minutes > 0) {
          return `${hours}小时${minutes}分钟`;
        } else {
          return `${hours}小时`;
        }
      }
    };

    const articleTypeMap = {
      [ArticleContentType.SCIENCE_KNOWLEDGE]: '推荐知识',
      [ArticleContentType.MEDICAL_KNOWLEDGE]: '目录知识',
    };

    const columns = [
      { header: '文章ID', key: '文章ID', width: 20 },
      { header: '文章标题', key: '文章标题', width: 50 },
      { header: '文章类型', key: '文章类型', width: 20 },
      { header: '疾病类别', key: '疾病类别', width: 20 },
      { header: '作者', key: '作者', width: 20 },
      { header: '阅读/次', key: '阅读/次', width: 20 },
      { header: '点赞/次', key: '点赞/次', width: 20 },
      { header: '收藏/次', key: '收藏/次', width: 20 },
      { header: '分享/次', key: '分享/次', width: 20 },
      // 阅读时长、平均阅读时长
      { header: '阅读时长', key: '阅读时长', width: 20 },
      { header: '平均阅读时长', key: '平均阅读时长', width: 20 },
    ];

    const articleList: ArticleContentEntity[] = await this.articleContentService.findAll();

    if (articleList.length > 0) {
      const formattedData = await Promise.all(
        articleList.map(async (article) => {
          const articleWithStats = await this.addArticleStats(article);

          return {
            文章ID: article?.id ?? '-',
            文章标题: article?.name ?? '-',
            文章类型: articleTypeMap[article?.type] ?? '-',
            疾病类别: article?.category?.name ?? '-',
            作者: article?.author ?? '-',
            '阅读/次': article?.viewCount ?? 0,
            '点赞/次': article?.likeCount ?? 0,
            '收藏/次': article?.collectCount ?? 0,
            '分享/次': article?.shareCount ?? 0,
            阅读时长: formatReadingTime(articleWithStats?.readTime || 0) ?? '-',
            平均阅读时长: formatReadingTime(articleWithStats?.averageReadTime || 0) ?? '-',
          };
        })
      );

      return { columns, data: formattedData };
    }

    return { columns, data: [] };
  }

  /**
   * 导出面板反馈列表数据
   * @returns 包含列和数据的对象
   */
  async exportPanelFeedbackList(): Promise<{
    columns: Record<string, any>[];
    data: Record<string, any>[];
  }> {
    // 反馈状态映射
    const statusMap = {
      NEW: '新建',
      PROCESSING: '处理中',
      COMPLETED: '已完成',
      REJECTED: '已拒绝',
    };

    const columns = [
      { header: '用户昵称', key: '用户昵称', width: 30 },
      { header: '用户手机号', key: '用户手机号', width: 30 },
      { header: '反馈内容', key: '反馈内容', width: 50 },
      { header: '反馈时间', key: '反馈时间', width: 30 },
      { header: '处理状态', key: '处理状态', width: 20 },
    ];

    const feedbackList: Record<string, any>[] = await this.feedbackService.getAllFeedbacks();

    if (feedbackList && feedbackList.length > 0) {
      const formattedData = feedbackList.map((feedback) => ({
        用户昵称: feedback?.nickname ?? '',
        用户手机号: feedback?.phone ?? '',
        反馈内容: feedback?.feedbackContent ?? '',
        反馈时间: dayjs(feedback.createdAt).format('YYYY-MM-DD HH:mm:ss'),
        处理状态: statusMap[feedback.feedbackStatus] ?? '',
      }));

      return {
        columns: columns,
        data: formattedData,
      };
    }

    return {
      columns: columns,
      data: feedbackList,
    };
  }

  /**
   * 导出面板积分日志列表数据
   * @returns 包含列和数据的对象
   */
  async exportPanelPointsLogList(): Promise<{
    columns: Record<string, any>[];
    data: Record<string, any>[];
  }> {
    const columns = [
      { header: '用户昵称', key: '用户昵称', width: 30 },
      { header: '手机号', key: '手机号', width: 30 },
      { header: '积分来源', key: '积分来源', width: 30 },
      { header: '积分变动类型', key: '积分变动类型', width: 20 },
      { header: '积分变动', key: '积分变动', width: 20 },
      { header: '变动时间', key: '变动时间', width: 30 },
			// { header: '关联数据', key: '关联数据', width: 30 },
      { header: '文章编码', key: '文章编码', width: 20 },
      { header: '文章标题', key: '文章标题', width: 30 },
      // 问卷标题、答题标题
      { header: '问卷标题', key: '问卷标题', width: 30 },
      { header: '答题标题', key: '答题标题', width: 30 },
    ];

    const pointsLogList: Record<string, any>[] = await this.pointsLogService.getAllPointsLogs();

    if (pointsLogList && pointsLogList.length > 0) {
      const formattedData = pointsLogList.map((points) => {
        const item = {
          用户昵称: points?.nickname ?? '-',
          手机号: points?.phone ?? '-',
          积分来源: points?.title ?? '-',
          积分变动类型: points?.type === 0 ? '支出' : points?.type === 1 ? '收入' : '-',
          积分变动: points?.points ?? '-',
          变动时间: dayjs(points.createdAt).format('YYYY-MM-DD HH:mm:ss'),
					// 关联数据: points?.missionRelatedData ?? '-',
          文章编码: points?.articleCode ?? '-',
          文章标题: points?.articleName ?? '-',
					问卷标题: points?.surveyName && points?.missionType === MissionType.EXAM ? points?.surveyName : '-',
					答题标题: points?.surveyName && points?.missionType === MissionType.QNAIRE ? points?.surveyName : '-',
        };

        return item;
      });

      return {
        columns,
        data: formattedData,
      };
    }

    return {
      columns,
      data: [],
    };
  }

  /**
   * 导出文章阅读数据
   * @returns 包含列和数据的对象
   */
  async exportPanelArticleLogList(): Promise<{
    columns: Record<string, any>[];
    data: Record<string, any>[];
  }> {
    const ArticleContentTypeName = {
      SCIENCE_KNOWLEDGE: '推荐知识', // 科普知识 - 推荐知识
      MEDICAL_KNOWLEDGE: '目录知识', // 医学知识 - 任务知识
    };

    const columns = [
      { header: '文章编码', key: '文章编码', width: 20 },
      { header: '文章标题', key: '文章标题', width: 30 },
      { header: '文章类型', key: '文章类型', width: 30 },
      { header: '关联疾病', key: '关联疾病', width: 30 },
      { header: '作者', key: '作者', width: 20 },
      { header: '用户昵称', key: '用户昵称', width: 30 },
      { header: '用户手机号', key: '用户手机号', width: 30 },
      { header: '阅读时长/秒', key: '阅读时长/秒', width: 20 },
      { header: '阅读开始时间', key: '阅读开始时间', width: 30 },
      { header: '阅读结束时间', key: '阅读结束时间', width: 30 },
    ];

    const articleLogList: Record<string, any>[] = await this.logService.getAllArticleLogs();

    if (articleLogList && articleLogList.length > 0) {
      const formattedData = articleLogList.map((log) => ({
        文章编码: log?.articleCode ?? '-',
        文章标题: log?.articleName ?? '-',
        文章类型: ArticleContentTypeName[log?.articleType] ?? '-',
        关联疾病: log?.articleCategoryName ?? '-',
        作者: log?.articleAuthor ?? '-',
        用户昵称: log?.nickname ?? '-',
        用户手机号: log?.phone ?? '-',
        '阅读时长/秒': log?.readDuration ?? 0,
        阅读开始时间: dayjs(log.createdAt)
          .subtract(log?.readDuration || 0, 'second')
          .format('YYYY-MM-DD HH:mm:ss'),
        阅读结束时间: dayjs(log.createdAt).format('YYYY-MM-DD HH:mm:ss'),
      }));

      return {
        columns,
        data: formattedData,
      };
    }

    return {
      columns,
      data: [],
    };
  }

  /**
   * 导出文章评分数据
   * @returns 评分数据
   */
  async exportPanelArticleReviewLogList(): Promise<{
    columns: Record<string, any>[];
    data: Record<string, any>[];
  }> {
    const columns = [
      { header: '文章编码', key: '文章编码', width: 20 },
      { header: '文章标题', key: '文章标题', width: 30 },
      { header: '用户昵称', key: '用户昵称', width: 30 },
      { header: '用户手机号', key: '用户手机号', width: 30 },
      { header: '帮助评分', key: '帮助评分', width: 30 },
      { header: '推送满意度评分', key: '推送满意度评分', width: 30 },
      { header: '内容满意度评分', key: '内容满意度评分', width: 30 },
      { header: '评分时间', key: '评分时间', width: 30 },
    ];

    const articleReviewList: Record<string, any>[] =
      await this.articleContentUserReviewService.getAllArticleReview();

    if (articleReviewList && articleReviewList.length > 0) {
      const formattedData = articleReviewList.map((review) => ({
        文章编码: review?.articleCode ?? '-',
        文章标题: review?.articleName ?? '-',
        用户昵称: review?.nickname ?? '-',
        用户手机号: review?.phone ?? '-',
        帮助评分: review?.helpfulnessScore ?? '-',
        推送满意度评分: review?.pushSatisfactionScore ?? '-',
        内容满意度评分: review?.contentSatisfactionScore ?? '-',
        评分时间: dayjs(review.createdAt).format('YYYY-MM-DD HH:mm:ss'),
      }));

      return {
        columns,
        data: formattedData,
      };
    }

    return { columns, data: [] };
  }

  /**
   * 统计关联数据
   * @returns
   */
  async exportPanelArticleRelatedCountList(): Promise<
    {
      columns: Record<string, any>[];
      data: Record<string, any>[];
      name: string;
    }[]
  > {
    let [likeData, collectData, shareData] = [[], [], []];

    const likeColumns = [
      { header: '文章编码', key: '文章编码', width: 20 },
      { header: '文章标题', key: '文章标题', width: 30 },
      { header: '用户昵称', key: '用户昵称', width: 30 },
      { header: '用户手机号', key: '用户手机号', width: 30 },
      { header: '点赞时间', key: '点赞时间', width: 30 },
    ];

    const collectColumns = [
      { header: '文章编码', key: '文章编码', width: 20 },
      { header: '文章标题', key: '文章标题', width: 30 },
      { header: '用户昵称', key: '用户昵称', width: 30 },
      { header: '用户手机号', key: '用户手机号', width: 30 },
      { header: '收藏时间', key: '收藏时间', width: 30 },
    ];

    const shareColumns = [
      { header: '文章编码', key: '文章编码', width: 20 },
      { header: '文章标题', key: '文章标题', width: 30 },
      { header: '用户昵称', key: '用户昵称', width: 30 },
      { header: '用户手机号', key: '用户手机号', width: 30 },
      { header: '转发时间', key: '转发时间', width: 30 },
    ];

    const likeCount: Record<string, any>[] = await this.articleContentLikeService.getAllCount();

    if (likeCount && likeCount.length) {
      likeData = likeCount.map((content) => {
        return {
          文章编码: content.articleCode,
          文章标题: content.articleName,
          用户昵称: content.nickname,
          用户手机号: content.phone,
          点赞时间: dayjs(content.createdAt).format('YYYY-MM-DD HH:mm:ss'),
        };
      });
    }

    const collectCount: Record<string, any>[] =
      await this.articleContentCollectService.getAllCount();

    if (likeCount && likeCount.length) {
      collectData = collectCount.map((content) => {
        return {
          文章编码: content.articleCode,
          文章标题: content.articleName,
          用户昵称: content.nickname,
          用户手机号: content.phone,
          收藏时间: dayjs(content.createdAt).format('YYYY-MM-DD HH:mm:ss'),
        };
      });
    }

    const shareCount: Record<string, any>[] = await this.articleContentShareService.getAllCount();

    if (likeCount && likeCount.length) {
      shareData = shareCount.map((content) => {
        return {
          文章编码: content.articleCode,
          文章标题: content.articleName,
          用户昵称: content.nickname,
          用户手机号: content.phone,
          转发时间: dayjs(content.createdAt).format('YYYY-MM-DD HH:mm:ss'),
        };
      });
    }

    return [
      {
        name: '点赞情况',
        columns: likeColumns,
        data: likeData,
      },
      {
        name: '收藏情况',
        columns: collectColumns,
        data: collectData,
      },
      {
        name: '转发情况',
        columns: shareColumns,
        data: shareData,
      },
    ];
  }
}
